/*
 * Copyright (c) 2024 Huawei Technologies Co.,Ltd.
 *
 * openGauss is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *
 * http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 * -------------------------------------------------------------------------
 *
 * htap_helpers.h
 * Helper function definitions for HTAP.Holds global configuration for the HTAP module.
 *
 * IDENTIFICATION
 * src/include/storage/htap/htap_helpers.h
 *
 * -------------------------------------------------------------------------
 */

#ifndef HTAP_HELPERS_H
#define HTAP_HELPERS_H

#include "catalog_column_types.h"
#include "nodes/primnodes.h"
#include "global.h"
#include "mot_engine.h"
#include "icsn_manager.h"

namespace htap {
extern void HTAPDestroySession(MOT::SessionContext *sessionContext);
extern void HTAPInitSessionDetailsMap();
extern void HTAPDestroySessionDetailsMap();
extern void HTAPRecordSessionDetails();
extern void HTAPClearSessionDetails(MOT::SessionId sessionId);
extern void HTAPClearCurrentSessionDetails();
extern void HTAPGetSessionDetails(MOT::SessionId sessionId, ::ThreadId *gaussSessionId, pg_time_t *sessionStartTime);
extern void HTAPInitSessionCleanup();
extern void HTAPDestroySessionCleanup();
extern void HTAPScheduleSessionCleanup();
extern void HTAPCancelSessionCleanup();
extern void HTAPOnSessionClose();
extern void HTAPOnThreadShutdown();
extern void HTAPCleanupThread(int status, Datum ptr);

/**
 * @brief Initializes thread local members.
 */
extern bool HTAPEnsureSafeThreadAccess();

/**
 * @brief Creates or retrieves MOT transaction manager.
 * @param collerSrc function name which has called it
 * @param txn_id transaction id
 */
extern MOT::TxnManager *HTAPGetSafeTxn(::TransactionId txn_id = 0);
} // namespace htap

#endif // HTAP_HELPERS_H
